<?php
/**
 * @link https://www.kancloud.cn/cleverstone/ymb2
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

/* ----------- 树组件视图 ----------- */
/** @var \yii\web\View $this 当前视图实例 */
/** @var \builder\tree\TreeBuilder $context 当前树组件构建器实例 */
/** @var array $rootLayout 根布局 */
/** @var array $treeLayout 树布局 */
/** @var boolean $switchCheckedBtn 是否显示全选/反选按钮 */
/** @var boolean $switchSpreadBtn 是否显示展开/折叠按钮 */
/** @var array $operationItem 自定义操作项 ['top' => [...], 'bottom' => [...]] */

$context = $this->context;
?>
<div id="__YM2_BUILDER_ID__<?= $context->id ?>" class="p-3 <?= $rootLayout['class'] ?>" ng-controller="ym2.ctrl.<?= $context->id ?>" style="<?= $rootLayout['style'] ?>"<?= $rootLayout['attribute'] ?>>

    <!--tree开始-->
    <?= $context->beginTree() ?>

    <!--操作-->
<?php if (
        $switchCheckedBtn
        || $switchSpreadBtn
        || !empty($operationItem['top'])
): ?>

    <div class="layui-btn-container btn-top-group">
<?php if ($switchCheckedBtn): ?>

        <button type="button" class="css-toggle-checked layui-btn layui-btn-sm layui-btn-primary ml-3" ng-click="toggleAll()">
            <span>全选/反选</span>
        </button>
<?php endif; ?>

<?php if ($switchSpreadBtn): ?>
        <button type="button" class="css-toggle-spread layui-btn layui-btn-sm layui-btn-primary" ng-click="toggleSpread()">
            <span>展开/折叠</span>
        </button>
<?php endif; ?>

<?php if (!empty($operationItem['top'])): ?>
<?php foreach ($operationItem['top'] as $item): ?>
        <button class="css-btn-custom layui-btn layui-btn-sm <?= $item['btnClass'] ?>" lay-on="<?= $item['options']['__event_id'] ?>">
<?php if (!empty($item['icon'])): ?>
            <span class="<?= $item['icon'] ?>"></span>
<?php endif; ?>
            <?= $item['title'] ?>
        </button>
<?php endforeach; ?>
<?php endif; ?>
    </div>
<?php endif; ?>

    <!--树组件-->
    <div id="ym2_builder_<?= $context->id ?>" class="<?= $treeLayout['class'] ?>" style="<?= $treeLayout['style'] ?>"<?= $treeLayout['attribute'] ?>></div>

    <!--操作-->
<?php if (!empty($operationItem['bottom'])): ?>
    <div class="layui-card-body">
        <div class="layui-btn-container btn-bottom-group">
<?php foreach ($operationItem['bottom'] as $item): ?>
            <button class="css-btn-custom layui-btn layui-btn-sm <?= $item['btnClass'] ?>" lay-on="<?= $item['options']['__event_id'] ?>">
<?php if (!empty($item['icon'])): ?>
                <span class="<?= $item['icon'] ?>"></span>
<?php endif; ?>
                <?= $item['title'] ?>
            </button>
<?php endforeach; ?>
        </div>
    </div>
<?php endif; ?>

    <!--tree结束-->
    <?= $context->endTree() ?>

</div>